using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Game : MonoBehaviour {

	public enum GAME_STATUS { 
		Ready,
		Game,
		Dead
	}

	private GAME_STATUS status;
	public GAME_STATUS Status {
		get { return status; }
		set 
		{ 
			status = value;
			UpdateUI();
		}
	}

	public GameObject uiReady;
	public GameObject uiGame;
	public GameObject uiDead;
	public PipelineManager pipelineManager;
	public Player player;

	public int score;
	public Text uiScore;
	public Text uiScore2;
	public int Score
	{
		get { return score; }
		set {
			this.score = value;
			this.uiScore.text = this.score.ToString();
			this.uiScore2.text = this.score.ToString();
		}
	}


	// Use this for initialization
	void Start () {
		uiReady.SetActive(true);
		Status = GAME_STATUS.Ready;
        this.player.OnDeath += Player_OnDeath;
		this.player.OnScore = OnPlayerScore;
	}

	private void OnPlayerScore( int score)
	{
		this.Score += score;
	}

    private void Player_OnDeath()
    {
		this.Status = GAME_STATUS.Dead;
		pipelineManager.Stop();


	}

    // Update is called once per frame
    void Update () {
		
	}

	public void StartGame() {
		//开始游戏
		this.Status = GAME_STATUS.Game;
		pipelineManager.StartRun();
		Debug.LogFormat("StartGame()调用, GAME_STATUS = {0}", this.Status);
	}

	public void Restart()
	{
		this.Status = GAME_STATUS.Ready;
		pipelineManager.Init();
		player.Init();
	}

	public void UpdateUI() {
		this.uiReady.SetActive(this.Status == GAME_STATUS.Ready);
		this.uiGame.SetActive(this.Status == GAME_STATUS.Game);
		this.uiDead.SetActive(this.Status == GAME_STATUS.Dead);
	}
}
